{% extends "personal_center/base.html" %}
<!--固定资产付款创建页-->
{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" href="../../static/personnel/TimeSelector/skin/jedate.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        tr {
            height: 37px;
        }

        th {
            text-align: center;
        }

        tbody td {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        td:first-child, th:first-child {
            position: sticky;
            left: 0; /* 首行永远固定在左侧 */
            z-index: 1;
        }

        thead tr th {
            position: sticky;
            top: 0; /* 列首永远固定在头部  */
            background-color: #E8E8E8;
        }

        th:first-child {
            z-index: 2;
        }

        #tb_1 tr:hover {
            background: #cfcfcf;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        .jeinput_1{
            display: inline-block;
            width: 100%;
            padding-left: 10px;
            height: 36px;
            line-height: 34px\9;
            border: none;
            background-color: #fff;
            border-radius: 3px;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <span> 新增申请</span>
            </a>
        </div>

        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 30px;"
                    onclick="save_data()">
                保&nbsp;&nbsp;存
            </button>
        </div>

        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 30px;"
                    onclick="ExportCar()">
                提&nbsp;&nbsp;交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 95%;height: auto;display: inline-block;vertical-align: center;margin-left: 2.5%;">
                <div style="width: 100%">
                    <table style="width: 100%;margin-top: 1%;">
                        <tr style="width: 100%;">
                            <td colspan="4" style="height: 40px;text-align: center;border: #cfcfcf solid 0.5px;"><h3>离&nbsp;职&nbsp;申&nbsp;请</h3></td>
                        </tr>
                        <tr>
                            <td colspan="4"
                                style="border: #cfcfcf solid 0.5px;width: 95%;margin-left: 2.5%;margin-top: 1%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;">
                                基本信息
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 37px;line-height: 37px;padding-right: 1%;">
                                申&nbsp;&nbsp;请&nbsp;人
                            </td>
                            <td id="user"
                                style="width: 40%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">
                                {{ obj.user.real_name }}
                            </td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 0.9%;letter-spacing: 2px;">
                                工&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号
                            </td>
                            <td id="job_number"
                                style="width: 40%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ obj.user.job_number }}
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                所属科室
                            </td>
                            <td id="company"
                                style="width: 40%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ obj.company.name }}
                            </td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 0.9%;letter-spacing: 2px;">
                                职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称
                            </td>
                            <td id="rank" style="width: 40%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;outline: none;">{{ obj.rank }}
                            </td>
                        </tr>

                        <tr>

                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;历
                            </td>
                            <td id="education" style="width: 40%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;padding-left: 1%">
                                {{ obj.education }}
                            </td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;letter-spacing: 6px;">
                                联系方式&nbsp;
                            </td>
                            <td id="tel_num"
                                style="width: 40%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ obj.tel_num }}
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                入职时间
                            </td>
                            <td style="width: 40%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;">
                                <input type="text" class="jeinput_1" id="test12" value="{{ obj.hiredate|date:'Y-m-d' }}">
                            </td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                拟离职时间
                            </td>
                            <td style="width: 40%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;">
                                <input type="text" class="jeinput_1" id="test13" value="{{ obj.dimission_time|date:'Y-m-d' }}">
                            </td>
                        </tr>

                        <tr style="width: 100%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                离职原因
                            </td>
                            <td style="width: 35%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: left;padding-left: 1%;">
                                <input type="text" id="dimission_note" style="width: 100%;height: 100%;border: none" value="{{ obj.dimission_note }}"></td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;letter-spacing: 6px;">
                                人员类别&nbsp;
                            </td>
                            <td style="width: 35%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: left;padding-left: 1%;">
                                <input type="radio" name="people_type" value="1" {% if obj.people_type == '1' %}checked{% endif %}> 行管
                                <input type="radio" name="people_type" value="2" style="margin-left: 20px;" {% if obj.people_type == '2' %}checked{% endif %}> 医技/临床
                                <input type="radio" name="people_type" value="3" style="margin-left: 20px;" {% if obj.people_type == '3' %}checked{% endif %}> 护理
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                离职须知
                            </td>
                            <td colspan="3"
                                style="color:red; width: 10%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: left;padding-left: 1%;">
                            1. 试用期员工需提前3天提出书面离职申请，转正员工需提前30天提出书面离职申请；<br>
                            2. 提交离职申请后请做好科室交接工作。
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main">
                        {% for record in file_list %}
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_name }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_size }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.upload_time }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.uploader }}</td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    <a target='_blank' href="{{ record.file_path }}">查看</a> | <a style="color: red;"
                                                                                                 href='#'
                                                                                                 onclick='RemoveTr(this, "party_main", {{ record.id }})'>删除</a>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/personnel/TimeSelector/src/jedate.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("personage").className = "add_class";
            document.getElementById("sponsor").className = "add-nav-active";
        };

        //自定义格式选择
        jeDate("#test12",{
            format: "YYYY-MM-DD"
        });

        jeDate("#test13",{
            format: "YYYY-MM-DD"
        });

        //一次绑定多个选择
        var jel = document.querySelectorAll(".moredate");
        for(var j=0;j<jel.length;j++){
            var mat = jel[j].getAttribute("placeholder");
            jeDate(jel[j],{
                format: mat
            });
        }

        //一次绑定多个选择DIV类型
        var divel = document.querySelectorAll(".divmore");
        for(var j=0;j<divel.length;j++){
            var divmat = divel[j].getAttribute("placeholder");
            jeDate(divel[j],{
                format: divmat
            });
        }

        const uuid = "{{ obj.fj_number | safe }}"
        const is_flag = "{{ is_flag }}"
        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'lzsq')       // 离职申请
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");
                    var td2 = document.createElement("td");
                    var td3 = document.createElement("td");
                    var td4 = document.createElement("td");
                    var td5 = document.createElement("td");
                    var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;
                    td1.style.textAlign = "center";
                    td1.style.border = "#cccccc solid 1px";
                    td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];
                    td2.style.paddingLeft = "1%";
                    td2.style.border = "#cccccc solid 1px";
                    td2.style.borderLeft = "none";
                    td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];
                    td3.style.textAlign = "center";
                    td3.style.border = "#cccccc solid 1px";
                    td3.style.borderLeft = "none";
                    td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];
                    td4.style.textAlign = "center";
                    td4.style.border = "#cccccc solid 1px";
                    td4.style.borderLeft = "none";
                    td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];
                    td5.style.textAlign = "center";
                    td5.style.border = "#cccccc solid 1px";
                    td5.style.borderLeft = "none";
                    td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";
                    td6.style.border = "#cccccc solid 1px";
                    td6.style.borderLeft = "none";
                    td6.style.borderTop = "none";
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    tr.appendChild(td5);
                    tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                var tr = document.createElement("tr");
                var td1 = document.createElement("td");
                var td2 = document.createElement("td");
                var td3 = document.createElement("td");
                var td4 = document.createElement("td");
                var td5 = document.createElement("td");
                var td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;
                td1.style.textAlign = "center";
                td1.style.border = "#cccccc solid 1px";
                td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];
                td2.style.paddingLeft = "1%";
                td2.style.border = "#cccccc solid 1px";
                td2.style.borderLeft = "none";
                td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];
                td3.style.textAlign = "center";
                td3.style.border = "#cccccc solid 1px";
                td3.style.borderLeft = "none";
                td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];
                td4.style.textAlign = "center";
                td4.style.border = "#cccccc solid 1px";
                td4.style.borderLeft = "none";
                td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];
                td5.style.textAlign = "center";
                td5.style.border = "#cccccc solid 1px";
                td5.style.borderLeft = "none";
                td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";
                td6.style.border = "#cccccc solid 1px";
                td6.style.borderLeft = "none";
                td6.style.borderTop = "none";
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function save_data() {
            var hiredate = document.getElementById("test12").value;                   // 入职时间
            var dimission_time = document.getElementById('test13').value;                       // 离职时间
            var dimission_note = document.getElementById('dimission_note').value;       // 离职原因
            if (!hiredate) {
                alert('请选择入职时间！');
                return false
            }
            if (!dimission_time) {
                alert('请选择拟离职时间！');
                return false
            }
            var people_type = $("input[type=radio][name=people_type]:checked").val();
            var str_word = "id={{ obj.id }}&hiredate=" + hiredate + "&dimission_time=" + dimission_time + "&dimission_note=" + dimission_note + "&fj_number=" + String(uuid)+"&people_type="+people_type

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/dimission_apply_draft_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(str_word);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert(JsonDate["message"])
                            window.location.href = "/finance/dimission_apply_list_view"
                        } else {
                            alert(JsonDate["message"])
                        }
                    }
                }
            };
        }

        function ExportCar() {
            var hiredate = document.getElementById("test12").value;                   // 入职时间
            var dimission_time = document.getElementById('test13').value;                       // 离职时间
            var dimission_note = document.getElementById('dimission_note').value;       // 离职原因
            var people_type = $("input[type=radio][name=people_type]:checked").val();

            if (!dimission_note) {
                alert("离职原因不能为空！");
                return false
            }
            if (!hiredate) {
                alert('请选择入职时间！');
                return false
            }
            if (!dimission_time) {
                alert('请选择拟离职时间！');
                return false
            }
            if (!people_type) {
                alert('请选择人员类别！');
                return false
            }
            var str_word = "id={{ obj.id }}&hiredate=" + hiredate + "&dimission_time=" + dimission_time + "&dimission_note=" + dimission_note + "&fj_number=" + String(uuid)+"&people_type="+people_type

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/dimission_apply_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(str_word);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert(JsonDate["message"])
                            window.location.href = "/finance/dimission_apply_list_view"
                        } else {
                            alert(JsonDate["message"])
                        }
                    }
                }
            };
        }
    </script>
{% endblock %}
